//
//  Young_Merchant_ViewController.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/4/21.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "Young_Merchant_ViewController.h"
#import "UpdateGeRenInFoViewController.h"
#import "UpdatePasswordViewController.h"
#import "ApplyForViewController.h"
#import "GeRenView.h"
#import "Merchant_View.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "BassViewController.h"
#import "ResetPasswordViewController.h"
#import "AccountViewController.h"
#import "NewsInfoViewController.h"
#import "RecommendNewViewController.h"
#import "DataDownloadViewController.h"
#import "OfflineViewController.h"
#import "PowerViewController.h"
#import "HierarchyViewController.h"
#import "CommissionViewController.h"
#import "InventoryViewController.h"
#import "ChooseLineViewController.h"
#import "InfoViewController.h"
#import "BindingViewController.h"

#import "InformationButton.h"
#import "FinishWithDrawViewController.h"
#import "AlertView.h"
#import "YoungAllData.h"
#import "LoginViewController.h"
#import "CertificationViewController.h"
#import "LogisticsListInFoViewController.h"

@interface Young_Merchant_ViewController ()<UITextFieldDelegate,UITextViewDelegate,UIScrollViewDelegate,YoungDelegate>
{
    UIScrollView *zScrollView;
    UIView *_loginAlertBackview;
    AlertView *_loginAlerView;
    UIButton *titleBtn;
    UIButton *lookUpBtn;//查看库存
}
@property (nonatomic,strong) UIScrollView *mainmainScrollView;
@property(nonatomic,retain)NSString *levelName;
@end

@implementation Young_Merchant_ViewController
@synthesize nameTextField,mobileTextField,addressTextView,editBtn,levelName;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    self.navigationController.navigationBar.hidden = YES;
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    title.textAlignment = NSTextAlignmentCenter;
    title.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    title.text = @"个人中心";
    title.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = title;
    InformationButton *infonmationBut = [[InformationButton alloc] initWithFrame:CGRectMake(0, 0, 23, 29)];
    infonmationBut.informationNum.text = @"20";
    [infonmationBut setBackgroundImage:[UIImage imageNamed:@"查看库存_03"] forState:UIControlStateNormal];
    [infonmationBut addTarget:self action:@selector(informationClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBut = [[UIBarButtonItem alloc] initWithCustomView:infonmationBut];
    self.navigationItem.rightBarButtonItem = rightBut;
    
    self.mainmainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    if (SCREEN_HEIGHT < 568) {
        self.mainmainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*1.2);
    }
    [self.view addSubview:self.mainmainScrollView];
    
    
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainUserInfo:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"]];
    
}
int iNum = 1;
- (void)requistFailGeRen{
    if (iNum == 4) {
        return;
    }
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainUserInfo:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"]];
    iNum++;
}
#pragma mark - 是否有申请升级的机会
-(void)isUpgrade:(NSDictionary *)sign{
    NSLog(@"%@",sign);
    //切换微商客户
    //[self createGeRenView];
    if ([[sign objectForKey:@"status"]isEqualToString:@"success"]) {
        [self createMerchantView:@"YES"];
    }else{
        [self createMerchantView:@"NO"];
    }
}
#pragma mark - 申请升级失败
-(void)requistFail{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 微商账户信息回调
-(void)userInfo:(NSDictionary *)sign{
    NSLog(@"%@",[[sign objectForKey:@"data"] objectForKey:@"LevelID"]);
    levelName = [[sign objectForKey:@"data"] objectForKey:@"LevelID"];
    //[self createMerchantView:[[sign objectForKey:@"data"] objectForKey:@"LevelName"]];
    if ([[[sign objectForKey:@"data"] objectForKey:@"LevelID"] isEqualToString:@"2"] ||[[[sign objectForKey:@"data"] objectForKey:@"LevelName"] isEqualToString:@"3"] ) {
        [self createMerchantView:@"V"];
    }else{
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate = self;
        [data isUpgrade:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"]];
    }
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;
}

#pragma -mark 普通用户View
- (void)createGeRenView{
    
    //普通用户
    //    GeRenView *geRenView = (GeRenView *)[[[NSBundle mainBundle] loadNibNamed:@"GeRen_xibs" owner:self options:nil] firstObject];
    //    [geRenView.compileBut addTarget:self action:@selector(updateGeRenInfo) forControlEvents:UIControlEventTouchUpInside];
    //    [geRenView.ChangePassword addTarget:self action:@selector(updatePassword) forControlEvents:UIControlEventTouchUpInside];
    //    [geRenView.becomeMerchantBut addTarget:self action:@selector(becomeMerchantButClick) forControlEvents:UIControlEventTouchUpInside];
    //
    //    geRenView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    //    [self.mainmainScrollView addSubview:geRenView];
    
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    backgroundView.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    backgroundView.userInteractionEnabled = YES;
    [self.view addSubview:backgroundView];
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 130)];
    topView.backgroundColor = [UIColor whiteColor];
    [backgroundView addSubview:topView];
    
    
    nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 20 ,100 , 14)];
    nameTextField.font = [UIFont systemFontOfSize:14];
    nameTextField.text = @"吴彦祖";
    nameTextField.backgroundColor= [UIColor whiteColor];
    [topView addSubview:nameTextField];
    [nameTextField setEnabled:NO];
    nameTextField.delegate = self;
    
    mobileTextField = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, 20 ,SCREEN_WIDTH/2-20 , 14)];
    mobileTextField.font = [UIFont systemFontOfSize:14];
    mobileTextField.text = @"电话:156-0202-3652";
    mobileTextField.textAlignment = NSTextAlignmentRight;
    mobileTextField.backgroundColor= [UIColor whiteColor];
    [topView addSubview:mobileTextField];
    [mobileTextField setEnabled:NO];
    mobileTextField.delegate = self;
    
    addressTextView = [[UITextView alloc] initWithFrame:CGRectMake(15, nameTextField.bottom+10 ,SCREEN_WIDTH-30 , 42)];
    addressTextView.font = [UIFont systemFontOfSize:14];
    addressTextView.text = @"北京市朝阳区奥运村街道安外北苑40号院街道安外北苑40号院";
    addressTextView.textAlignment = NSTextAlignmentLeft;
    addressTextView.backgroundColor= [UIColor whiteColor];
    [topView addSubview:addressTextView];
    [addressTextView setEditable:NO];
    addressTextView.delegate = self;
    
    UIView *editView = [[UIView alloc]initWithFrame:CGRectMake(0, addressTextView.bottom+10, SCREEN_WIDTH, 34)];
    editView.backgroundColor = [self colorWithHexString:@"#F8F8F8"];
    editView.userInteractionEnabled = YES;
    [topView addSubview:editView];
    
    editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [editBtn setBackgroundImage:[UIImage imageNamed:@"个人主页_03"] forState:UIControlStateNormal];
    editBtn.frame = CGRectMake(SCREEN_WIDTH-20-41, 9, 41, 16);
    [editBtn addTarget:self action:@selector(clickEditBtn) forControlEvents:UIControlEventTouchUpInside];
    [editView addSubview:editBtn];
    
    
    //middle
    UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(0, topView.bottom+10, SCREEN_WIDTH, 100)];
    middleView.backgroundColor = [UIColor whiteColor];
    middleView.userInteractionEnabled = YES;
    [backgroundView addSubview:middleView];
    
    UILabel *discountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 20)];
    discountLabel.text = @"成为微商，最后可享受5.5折扣";
    discountLabel.font = [UIFont systemFontOfSize:16];
    discountLabel.textColor = [UIColor blackColor];
    discountLabel.textAlignment = NSTextAlignmentCenter;
    [middleView addSubview:discountLabel];
    
    UIButton *consigneeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [consigneeBtn setBackgroundImage:[UIImage imageNamed:@"个人主页_07"] forState:UIControlStateNormal];
    consigneeBtn.frame = CGRectMake((SCREEN_WIDTH-145)/2, discountLabel.bottom+20, 145, 30);
    [consigneeBtn addTarget:self action:@selector(clickConsigneeBtn) forControlEvents:UIControlEventTouchUpInside];
    [middleView addSubview:consigneeBtn];
    
    //third
    UIView *thirdView = [[UIView alloc]initWithFrame:CGRectMake(0, middleView.bottom+10, SCREEN_WIDTH, 50)];
    thirdView.backgroundColor = [UIColor whiteColor];
    thirdView.userInteractionEnabled = YES;
    [backgroundView addSubview:thirdView];
    
    UILabel *passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 15, 114, 20)];
    passwordLabel.text = @"密码安全等级:";
    passwordLabel.font = [UIFont systemFontOfSize:16];
    passwordLabel.textColor = [UIColor blackColor];
    passwordLabel.textAlignment = NSTextAlignmentLeft;
    [thirdView addSubview:passwordLabel];
    
    UILabel *passwordValue = [[UILabel alloc]initWithFrame:CGRectMake(passwordLabel.right, 15, 40, 20)];
    passwordValue.text = @"安全";
    passwordValue.font = [UIFont systemFontOfSize:16];
    passwordValue.textColor = [self colorWithHexString:@"#73B358"];
    passwordValue.textAlignment = NSTextAlignmentLeft;
    [thirdView addSubview:passwordValue];
    
    UIButton *updatePasswordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [updatePasswordBtn setBackgroundImage:[UIImage imageNamed:@"个人主页_11"] forState:UIControlStateNormal];
    updatePasswordBtn.frame = CGRectMake(SCREEN_WIDTH-105, 10, 85, 30);
    [updatePasswordBtn addTarget:self action:@selector(clickUpdatePasswordBtn) forControlEvents:UIControlEventTouchUpInside];
    [thirdView addSubview:updatePasswordBtn];
    
    //below
    UIView *belowView = [[UIView alloc]initWithFrame:CGRectMake(0, thirdView.bottom+10, SCREEN_WIDTH, 75)];
    belowView.backgroundColor = [UIColor whiteColor];
    belowView.userInteractionEnabled = YES;
    [backgroundView addSubview:belowView];
    
    UILabel *complainLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 15, SCREEN_WIDTH-40, 20)];
    complainLabel.text = @"投诉电话:010-12345678";
    complainLabel.font = [UIFont systemFontOfSize:16];
    complainLabel.textColor = [UIColor blackColor];
    complainLabel.textAlignment = NSTextAlignmentLeft;
    [belowView addSubview:complainLabel];
    
    UILabel *emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, complainLabel.bottom+5, SCREEN_WIDTH-40, 20)];
    emailLabel.text = @"建议邮箱:Proposal@cuk.com";
    emailLabel.font = [UIFont systemFontOfSize:16];
    emailLabel.textColor = [UIColor blackColor];
    emailLabel.textAlignment = NSTextAlignmentLeft;
    [belowView addSubview:emailLabel];
}

#pragma -mark 点击信封按钮事件
- (void)informationClick{
    
    InfoViewController *infomation =[[InfoViewController alloc] init];
    [self.navigationController pushViewController:infomation animated:YES];
}
#pragma mark - 编辑
-(void)clickEditBtn{
    UpdateGeRenInFoViewController *update = [[UpdateGeRenInFoViewController alloc]init];
    [self.navigationController pushViewController:update animated:YES];
}
#pragma mark - 申请微商
-(void)clickConsigneeBtn{
    ApplyForViewController *becomMerchant = [[ApplyForViewController alloc]init];
    [self.navigationController pushViewController:becomMerchant animated:YES];
}
#pragma mark - 修改密码
-(void)clickUpdatePasswordBtn{
    ResetPasswordViewController *reset = [[ResetPasswordViewController alloc]init];
    [self.navigationController pushViewController:reset animated:YES];
}
#pragma mark - 另一个
#pragma -mark 微商View
static int btnTag = 0;
- (void)createMerchantView:(NSString *)isUpgrade{
    
    
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    zScrollView  = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-50-64)];
    zScrollView.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    
    //2级
    if (SCREEN_HEIGHT<500) {
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT+20);
    }else{
        zScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-60);
    }
    //大V
    
    [self.view addSubview:zScrollView];
    
    UIView *backgroundView;
    //2级
    if (SCREEN_HEIGHT<500) {
        backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.75)];
    }else{
        backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.63)];
    }
    //大V
    
    
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.userInteractionEnabled = YES;
    [zScrollView addSubview:backgroundView];
    
    
    NSMutableArray *picArray = [[NSMutableArray alloc]initWithObjects:@"个人主页1_03",@"个人主页_12",@"个人主页-(2)_03",@"个人主页1_05",@"个人主页_14@2x",@"bangdingyinhangkalogo",@"个人主页1_07",@"个人主页_16",@"tuijianxinweishang", nil];
    btnTag = 0;
    
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            if (SCREEN_WIDTH == 320) {
                btn.frame = CGRectMake(30+100*i, 20+95*j, 60, 75);
            }else if (SCREEN_WIDTH == 375){
                btn.frame = CGRectMake(35+117.5*i, 20+107.5*j, 70, 87.5);
            }else{
                //414
                btn.frame = CGRectMake(42+120*i, 20+132.5*j, 90, 112.5);
                // }
            }
            [btn setBackgroundImage:[UIImage imageNamed:[picArray objectAtIndex:btnTag]] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
            [backgroundView addSubview:btn];
            btn.tag = btnTag;
            btnTag++;
        }
    }
    
    
    //只有大V，1，2级才有这个，其他时候隐藏不显示
    lookUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lookUpBtn.frame = CGRectMake(20, 190+115, SCREEN_WIDTH-40, 40);
    [lookUpBtn setBackgroundImage:[UIImage imageNamed:@"个人主页_0333"] forState:UIControlStateNormal];
    [lookUpBtn addTarget:self action:@selector(clickLookUp:) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:lookUpBtn];
    
    
    
    
    titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    titleBtn.frame = CGRectMake(20, backgroundView.bottom+20, SCREEN_WIDTH-40, 40);
    titleBtn.backgroundColor = [UIColor clearColor];
    [titleBtn setBackgroundImage:[UIImage imageNamed:@"gerenzhuye-shenqingshengji"] forState:UIControlStateNormal];
    [titleBtn addTarget:self action:@selector(pressShen) forControlEvents:UIControlEventTouchUpInside];
    [zScrollView addSubview:titleBtn];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, titleBtn.bottom+3, SCREEN_WIDTH, 20)];
    label.text = @"每30天仅有一次申请机会";
    label.textColor = [ UIColor blackColor];
    label.font = [UIFont systemFontOfSize:12];
    label.textAlignment = NSTextAlignmentCenter;
    [zScrollView addSubview:label];
    
    UIButton *belowBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    if (SCREEN_HEIGHT < 500) {
        belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-55+50+20, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
    }else{
        belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64+30+30, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
    }
    [belowBtn1 setBackgroundImage:[UIImage imageNamed:@"个人主页_24"] forState:UIControlStateNormal];
    [belowBtn1 addTarget:self action:@selector(clickBelowBtn) forControlEvents:UIControlEventTouchUpInside];
    [zScrollView addSubview:belowBtn1];
    
    int i = 0;
    
    NSLog(@"%@",levelName);
    
    if([levelName isEqualToString:@"4"]){
        i = 2;
    }else if([levelName isEqualToString:@"5"]){
        i = 3;
    }else{
        i = 0;
    }
   
    //根据登录用户的等级去做相应的处理和改变
    switch (i) {
        case 0:
            titleBtn.hidden = YES;
            label.hidden = YES;
            if (SCREEN_HEIGHT<500) {
                belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-55+20, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
            }else{
                belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64, SCREEN_WIDTH*0.9375,   SCREEN_WIDTH*0.125);
            }
            break;
        case 1:
            titleBtn.hidden = YES;
            label.hidden = YES;
            if (SCREEN_HEIGHT<500) {
                belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-55+20, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
            }else{
            belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
            }
            break;
        case 2:
            //2级
            if ([isUpgrade isEqualToString:@"YES"]) {
                
            }else{
                titleBtn.userInteractionEnabled = NO;
                
                [titleBtn setBackgroundImage:[UIImage imageNamed:@"gerenzhuye-shenqingshengji2"] forState:UIControlStateNormal];
            }
            break;
        case 3:
            //特约
            
            lookUpBtn.hidden = YES;
            
          
            if (SCREEN_HEIGHT<500) {
                
                    backgroundView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.79);
                belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, backgroundView.bottom+20, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
                titleBtn.frame = CGRectMake(20, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64, SCREEN_WIDTH-40, 40);
                label.frame =   CGRectMake(0, titleBtn.bottom+3, SCREEN_WIDTH, 20);

            }else{
                  belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
                  backgroundView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.53);
                titleBtn.frame = CGRectMake(20, backgroundView.bottom+10, SCREEN_WIDTH-40, 40);
                label.frame =   CGRectMake(0, titleBtn.bottom+3, SCREEN_WIDTH, 20);

            }
            
            if ([isUpgrade isEqualToString:@"YES"]) {
                
            }else{
                titleBtn.userInteractionEnabled = NO;
                //gerenzhuye-shenqingshengji2
                [titleBtn setBackgroundImage:[UIImage imageNamed:@"gerenzhuye-shenqingshengji2"] forState:UIControlStateNormal];
            }
            break;
        default:
            titleBtn.hidden = YES;
            label.hidden = YES;
            lookUpBtn.hidden = YES;
            belowBtn1.frame = CGRectMake(0.03125*SCREEN_WIDTH, SCREEN_HEIGHT-(SCREEN_WIDTH*0.125)-70-64-40, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
            if (SCREEN_HEIGHT<500) {
                backgroundView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.88);
            }else{
                backgroundView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.53);
            }
            
            break;
    }
    
    
    
    
    
    
    
}
#pragma mark - 发起升级申请接口
-(void)pressShen{
    //没有绑定银行卡
    NSString *isBank = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"IsBindBankcard"]];

    if ([isBank isEqualToString:@"0"]) {
        [self createAlertView];
    }else{
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate = self;
        [data sendApply:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"]];

    }
}
#pragma mark - 发起升级申请回调
-(void)apply:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"申请成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    
    titleBtn.userInteractionEnabled = NO;
    [titleBtn setBackgroundImage:[UIImage imageNamed:@"gerenzhuye-shenqingshengji2"] forState:UIControlStateNormal];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

#pragma mark - btn
-(void)clickUser:(UIButton *)sender{
    NSString *isBank = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"IsBindBankcard"]];
    NSString *isPay =[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"IsPayOffDeposit"]];//是否缴纳保证金
    if (sender.tag == 0) {
        //账号
        if ([isBank isEqualToString:@"0"]) {
            [self createAlertView];
        }else{
            AccountViewController *account = [[AccountViewController alloc]init];
            [self.navigationController pushViewController:account animated:YES];
        }
        //[self createBaoAlertView];
    }else if (sender.tag == 1){
        //授权书
        if ([isBank isEqualToString:@"0"]) {
            [self createAlertView];
        }else{
            if ([isPay isEqualToString:@"0"]) {
                [self createBaoAlertView];
            }else{
            PowerViewController *power = [[PowerViewController alloc]init];
            [self.navigationController pushViewController:power animated:YES];
            }
        }
    }else if (sender.tag == 3){
        //下线

        if ([isBank isEqualToString:@"0"]) {
            [self createAlertView];
        }else{
            if ([isPay isEqualToString:@"0"]) {
                [self createBaoAlertView];
            }else{
            OfflineViewController *offline = [[OfflineViewController alloc]init];
            offline.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:offline animated:YES];
            } 
        }
    }else if (sender.tag == 4){
        //等级制度
        HierarchyViewController *hierarchy = [[HierarchyViewController alloc]init];
        [self.navigationController pushViewController:hierarchy animated:YES];
    }else if (sender.tag == 2){
        //商品价格
        CommissionViewController *commission = [[CommissionViewController alloc]init];
        [self.navigationController pushViewController:commission animated:YES];
    }else if (sender.tag == 5){
        if ([isBank isEqualToString:@"1"]) {
            //已经绑定
            //暂时修改
            FinishWithDrawViewController *finish = [[FinishWithDrawViewController alloc]init];
            //finish.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:finish animated:YES];
//            CertificationViewController *offline = [[CertificationViewController alloc]init];//绑定状态
//            offline.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:offline animated:YES];
        }else{
            //如果银行卡没有绑定，就跳转实名认证
            CertificationViewController *offline = [[CertificationViewController alloc]init];//绑定状态
            //offline.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:offline animated:YES];
        }
//        YoungAllData *data = [[YoungAllData alloc]init];
//        data.delegate = self;
//        [data checkBank:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"]];
        
    }else if (sender.tag == 6){
        //资料
        DataDownloadViewController *data = [[DataDownloadViewController alloc]init];
        [self.navigationController pushViewController:data animated:YES];
    }else if (sender.tag == 7){
        //培训
        if ([isBank isEqualToString:@"0"]) {
            [self createAlertView];
        }else{
            if ([isPay isEqualToString:@"0"]) {
                [self createBaoAlertView];
            }else{
            NewsInfoViewController *new = [[NewsInfoViewController alloc]init];
            [self.navigationController pushViewController:new animated:YES];
            }
        }
    }else if (sender.tag == 8){
        //推荐新微商
        if ([isBank isEqualToString:@"0"]) {
            [self createAlertView];
        }else{
            if ([isPay isEqualToString:@"0"]) {
                [self createBaoAlertView];
            }else{
            ChooseLineViewController *recomment = [[ChooseLineViewController alloc]init];
            [self.navigationController pushViewController:recomment animated:YES];
            }
        }
    }
    
    
}
#pragma -mark 检查用户是否绑定银行卡
-(void)checkBank:(NSDictionary *)sign{
    NSLog(@"%@",sign);
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
        //已经绑定
        FinishWithDrawViewController *finish = [[FinishWithDrawViewController alloc]init];
        //finish.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:finish animated:YES];
    }else{
        BindingViewController *offline = [[BindingViewController alloc]init];//绑定状态
        //offline.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:offline animated:YES];

    }
    //绑定银行卡
    //两种情况 一种没绑定/另一种绑定
    

}
#pragma -mark 创建保证金提示框
- (void)createBaoAlertView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _loginAlertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _loginAlertBackview.backgroundColor = [UIColor blackColor];
    _loginAlertBackview.alpha = 0.4;
    [window addSubview:_loginAlertBackview];
    
    
    _loginAlerView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:10];
    _loginAlerView.frame = CGRectMake(50, SCREEN_HEIGHT/2.0-130/2.0, SCREEN_WIDTH-100, 130);
    [_loginAlerView.confirmBut addTarget:self action:@selector(confirmBaoClick) forControlEvents:UIControlEventTouchUpInside];
    [_loginAlerView.cancelBut addTarget:self action:@selector(cancelButClick) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:_loginAlerView];
    
    _loginAlerView.title.text = @"您还没有缴纳保证金";
    _loginAlerView.describeLabel1.text = @"请尽快缴纳";
    _loginAlerView.describeLabel2.text = @"缴纳保证金方可订购商品";
    [_loginAlerView.confirmBut setTitle:@"去缴纳" forState:UIControlStateNormal];
}
-(void)confirmBaoClick{
    [_loginAlerView removeFromSuperview];
    [_loginAlertBackview removeFromSuperview];
    AccountViewController *account = [[AccountViewController alloc]init];
    [self.navigationController pushViewController:account animated:YES];
}
#pragma -mark 创建提示框
- (void)createAlertView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _loginAlertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _loginAlertBackview.backgroundColor = [UIColor blackColor];
    _loginAlertBackview.alpha = 0.4;
    [window addSubview:_loginAlertBackview];
    
    
    _loginAlerView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:10];
    _loginAlerView.frame = CGRectMake(50, SCREEN_HEIGHT/2.0-130/2.0, SCREEN_WIDTH-100, 130);
    [_loginAlerView.confirmBut addTarget:self action:@selector(confirmButClick) forControlEvents:UIControlEventTouchUpInside];
    [_loginAlerView.cancelBut addTarget:self action:@selector(cancelButClick) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:_loginAlerView];
}
#pragma -mark 点击提示框去绑定银行卡事件
- (void)confirmButClick{
    [_loginAlerView removeFromSuperview];
    [_loginAlertBackview removeFromSuperview];
//    BindingViewController *bindingVC = [[BindingViewController alloc] init];
//    bindingVC.controller = self;
//    bindingVC.hidesBottomBarWhenPushed = YES;
//    
//    [self.navigationController pushViewController:bindingVC animated:YES];
    CertificationViewController *offline = [[CertificationViewController alloc]init];//绑定状态
   // offline.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:offline animated:YES];

}

#pragma -mark 点击提示框稍后按钮
- (void)cancelButClick{
    [_loginAlerView removeFromSuperview];
    [_loginAlertBackview removeFromSuperview];
    
}


#pragma mark - 查看库存
-(void)clickLookUp:(UIButton *)sender{
    //先将未到时间执行前的任务取消。
    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:sender];
    [self performSelector:@selector(todoSomething:) withObject:sender afterDelay:0.2f];

}
- (void)todoSomething:(id)sender
{
    //在这里做按钮的想做的事情。
    //没有绑定银行卡
    NSString *isBank = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"IsBindBankcard"]];
    if ([isBank isEqualToString:@"0"]) {
        [self createAlertView];
    }else{
        InventoryViewController *inventory = [[InventoryViewController alloc]init];
        [self.navigationController pushViewController:inventory animated:YES];
    }

}
#pragma mark - 推荐新微商
-(void)clickRightBtn{
    RecommendNewViewController *recomment = [[RecommendNewViewController alloc]init];
    [self.navigationController pushViewController:recomment animated:YES];
}
#pragma mark - 退出
-(void)clickBelowBtn{
    UIWindow *windown = [[[UIApplication sharedApplication] delegate] window];
    LoginViewController *loginVc = [[LoginViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVc];
    
    windown.rootViewController = nav;
}
#pragma mark - color
//传入字符串返回RGB
- (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
    
}
@end
